<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	public function __construct() {
        parent:: __construct();
        $this->load->model("Mposts");
        $this->load->library("pagination");
    }

	public function index()
	{
		$config = array();
		//$config['base_url'] = site_url('/home/index');
		$config['base_url'] = base_url();
		$config['total_rows'] = $this->Mposts->countAll();
		$config['per_page'] = 8;
		$config['uri_segment'] = 1;
    	$config['num_links'] = 5;
    	$config['use_page_numbers']  = TRUE;

		$this->pagination->initialize($config);

        $page = ($this->uri->segment(1)) ? $this->uri->segment(1) : 0;

        $data['posts'] = $this->Mposts->listPosts($config['per_page'], $page * $config['per_page'], 'A');
        $data['pagination'] = $this->pagination->create_links();

		$this->load->view('dashboard', array('data' => $data));
	}
}